;;; init-ediff.el --- Ediff configuration -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:

(defun ctrlwei/change-ediff-map ()
  (define-key ediff-mode-map "d" 'ediff-copy-both-to-C)
  (define-key ediff-mode-map "j" #'ediff-next-difference)
  (define-key ediff-mode-map "k" #'ediff-previous-difference))

(defun ctrlwei/ediff-copy-both-to-C ()
  (interactive)
  (ediff-copy-diff ediff-current-difference nil 'C nil
                   (concat
                    (ediff-get-region-contents ediff-current-difference 'A ediff-control-buffer)
                    (ediff-get-region-contents ediff-current-difference 'B ediff-control-buffer))))

(with-eval-after-load 'ediff
  (setq ediff-window-setup-function 'ediff-setup-windows-plain
        ediff-split-window-function 'split-window-horizontally
        ediff-merge-split-window-function 'split-window-horizontally)

  (add-hook 'ediff-keymap-setup-hook #'ctrlwei/change-ediff-map)
  (add-hook 'ediff-quit-hook #'winner-undo)
  (add-hook 'ediff-suspend-hook #'winner-undo))

(provide 'init-ediff)
;;; init-ediff.el ends here
